<template>
  <div class="box">
    <div class="aside">
      <div class="startSetting_navigate">
        <!-- 比赛参数 -->
        <RouterLink to="/startSetting/startSetting_1" active-class="startSetting_active">
          <div>.</div>
          <p>比赛参数</p>
        </RouterLink>

        <!-- 评分参数 -->
        <RouterLink to="/startSetting/startSetting_2" active-class="startSetting_active">
          <div>.</div>
          <p>评分参数</p>
        </RouterLink>
      </div>
    </div>
    <!-- 展示区 -->
    <div class="startSetting_main">
      <RouterView></RouterView>
      <!-- 按钮区 -->
      <div class="under_button">
        <button class="bt1" @click="tohome">取消</button>
        <button class="bt2" @click="submitFormData">创建</button>
      </div>
    </div>
  </div>
</template>
<script setup>
import './StartSetting_1.css'
import './StartSetting.css'
import { RouterLink } from 'vue-router'
import router from '../../router'
import { store } from '../../store'
import { ElMessage } from 'element-plus'

function tohome() {
  router.push('/start')
}
//获取初始表单数据
const initialFormData = JSON.parse(JSON.stringify(store.formData))
const submitFormData = () => {
  const form = store.formData
  form.jiangxiang = store.jiangxiang
  if (!form.time) {
    ElMessage.error('请填写比赛时间')
    return // 阻止后续代码执行
  }
  // if (form.xuanshou.length === 0) {
  //   ElMessage.error('请上传选手名单')
  //   return // 阻止后续代码执行
  // }

  const dataToSave = JSON.parse(JSON.stringify(form))

  window.electron.saveRoom(dataToSave).then((result) => {
    if (result.success) {
      ElMessage.success('数据保存成功')
      setTimeout(() => {
        tohome()
      }, 1000)
    } else {
      ElMessage.error('数据保存失败')
    }
  })
  store.formData = initialFormData // 重置表单数据
}
</script>
